/**
 * Created by Administrator on 2016/8/10 0010.
 */
import Vue from 'vue'
import resource from 'vue-resource'
Vue.use(resource)
var MyComponent = Vue.extend({
  template: [
    '<table class="table table-bordered table-condensed table-striped" style="word-break:break-all">',
    '<br/>',
    '<thead>',
    '<tr class="info" >',
    '<th></th> <th>原始名称</th> <th>最近更新者</th> <th>更新日期</th> <th>当前文件名</th> <th>上一级文件</th> <th>操作</th>',
    '</tr>',
    '</thead>',
    '<tbody>',
    '<tr v-for="item in items" track-by="$index" >',
    '<td><input type="checkbox" v-model="item.selected"></td>',
    '<td width="18%"><a href="#" >{{item.originname}} </a></td>',
    '<td width="5%">{{item.upduser}}</td>',
    '<td width="50%">{{item.upddate}}</td>',
    '<td width="12%">{{item.curname}}</td>',
    '<td>{{item.parent}}</td>',
    '<td>',
    '<a href="#" v-on:click="onRemoveItem(item,$event)"> 删除 </a> |',
    '<a href="#" v-on:click="onEditItem(item,$event)"> 编辑 </a>',
    '</td>',
    '</tr>',
    '</tbody>',
    '</table>'].join(''),
  data: function () {
    return {
      items: []
    }
  },
  props: {
    items: []
  },
  ready: function () {
  }
})

// 注册
Vue.component('nodelist', MyComponent)

var AppService = {
  urlroot: 'http://euvee.vicp.co/rest/fdb/',
  init: function () {
    Vue.http.options.root = this.urlroot
    Vue.http.headers.common['Token'] = window.localStorage.getItem('Token')
  },
  find: function (successCallback, errorCallback) {
    var url = this.urlroot
    Vue.http.get(url).then(successCallback, errorCallback)
  }
}
var svc = Object.create(AppService)

export default ({
  data: function () {
    return {
      msg: 'hello123',
      items: [],
      properties: [
        'id',
        'description',
        'deadline',
        'state',
        'principal'
      ]
    }
  },
  methods: {
    _find: function () {
      var self = this
      svc.find(function (response) {
        self.$set('items', response.data)
      }, function (response) {
      })
    }
  },
  ready: function () {
    svc.init()
    this._find()
  }
})
